<?php
/**
 * Description of PyramidAction
 *
 * @author Alen 2013-11-1
 */
class PyramidAction extends SoAction {
    
    protected  $USER_NAME;
    public function __construct() {
        parent::__construct();
        
        // 页面系统信息处理
        $this->assign('SKIN_FOLDER', 'Sites/Pyramid/Tpl/Default/Skin/');
        $this->assign('PAGE_TITLE','财富会社');
        $this->assign('PAGE_TITLE_SUFFIX', '财富会社商城');
        $this->assign('SITE_NAME','财富会社');
        $this->assign('SITE_DOMAIN','sochishun.com');
        $this->assign('PAGE_KEYWORD', '');
        $this->assign('PAGE_DESCRIPTION','');
        $this->assign('USER_IS_LOGIN', $this->check_user_login(false));
        
        // 页面框架信息处理
        $this->assign('head_menu', '');
        
    }
    
    /**
     * 检测用户是否登录,如果没有登录则跳转到登录页面
     * @param type $isredirect
     * @param type $url
     * @return boolean
     * @since 1.0.0 2013-10-8 sutroon
     */    
    protected function check_user_login($isredirect=true,$url='?m=Login'){
        $biz=new SoBizUser();
        $this->USER_NAME=$biz->get_login_info_param('USER_NAME');
        if($this->USER_NAME){
            $this->assign('USER_NAME', $this->USER_NAME);
            return true;
        }
        if($isredirect) redirect ('请登录...',$url);
        return false;
    }


    private function get_head_menu(){
        if(!$this->dm) $this->dm=new SoDataModule();
        $str='';
        $ds=$this->dm->select_arrayset('tgeneralcatalog', 'Level=1 and ParentID=0 and ExTags=\'PRODUCT_CATALOG\'','');
        foreach($ds as $row){
            $str.='';
        }        
    }
    
    /**
     * 设置页面信息
     * @param type $page_title
     * @param type $keywords
     * @param type $description
     * @param type $title_suffix
     * @since 1.0.0 2013-10-8 sutroon
     */
    private function set_page_info($page_title,$keywords='',$description='',$title_suffix=''){        
        if(!$this->dm) $this->dm=  new SoDataModule();
        $dataset=$this->dm->select_arrayset('tgeneraldata', 'ExTags=\'SITE_INFO\'','Name, Value');   
        if($dataset){
            $data=array();
            foreach($dataset as $row){
                $data[$row['Name']]=$row['Value'];
            } 
            // 如果站点状态是关闭，则显示网站关闭消息
            if(get_array_value($data, 'SITE_STATE')=='0') exit(get_array_value($data, 'SITE_CLOSE_MESSAGE'));
            // 页面标题为空的话读取后台配置信息
            if(!$page_title){
                $page_title=get_array_value($data, 'SITE_TITLE');
                $keywords=get_array_value($data, 'SITE_KEYWORDS');
                $description=get_array_value($data, 'SITE_DESCRIPTION');
                $title_suffix=  get_array_value($data, 'SITE_TITLE_SUFFIX');
            }
        }
        $this->assign('page_title',$page_title);
        $this->assign('page_title_suffix',$title_suffix);
        $this->assign('meta_keywords',$keywords);
        $this->assign('meta_description',$description);        
    }

    /**
     * 设置面包屑导航
     * @param type $arr
     * @example set_breadcrumb(array('文章管理'=>'?m=Article_List','编辑'=>'###'));
     * @since 1.0.0 2013-9-30 sutroon
     */
    protected function set_breadcrumb($arr){   
        $this->assign('breadcrumb',$this->uig->get_breadcrumb($arr));
    }
    
    /**
     * 设置页面标题
     * @param type $h1
     * @param type $small
     * @example set_h1('文章管理','在这里管理所有文章');
     * @since 1.0.0 2013-9-30 sutroon
     */
    protected function set_h1($h1,$small=''){
        $this->assign('pageheader', $this->uig->get_h1($h1,$small));
    }    
    
    /**
     * 获取编辑记录按钮
     * @param type $id
     * @param type $modname
     * @return type
     * @since 1.0.0 2013-10-3 sutroon
     * @example get_edit_linkbutton('article_edit',$row['ID']);
     */
    protected function get_edit_linkbutton($id,$modname){
        return $this->uig->get_linkbutton('编辑','?m='.$modname.'&id='.$id);
    }
    
    /**
     * 获取删除记录按钮
     * @param type $id
     * @param type $title
     * @return type
     * @since 1.0.0 2013-10-3 sutroon
     * @example get_delete_linkbutton($row['ID'],$row['Title']);
     */
    protected function get_delete_linkbutton($id,$title){
        return $this->uig->get_linkbutton('删除','###','id="#'.$id.'" title="'.$title.'" onclick="confirmADelete(this,\'?m=article_list&action=delete&id=.key.\')"');
    }
    
    /**
     * 获取编辑和删除记录等控制按钮
     * @param type $id
     * @param type $title
     * @param type $modname
     * @param type $btns
     * @param type $adduri 新增按钮的链接
     * @return string
     * @since 1.0.0 2013-10-3 sutroon
     */
    protected function get_control_linkbuttons($id,$title,$modname,$btns=array('edit','delete'),$adduri=''){
        $str='';
        foreach($btns as $btn){
            switch (strtolower($btn)){
                case 'edit':
                    $str.=$this->uig->get_linkbutton('编辑','?m='.$modname.'_Edit&id='.$id).' ';
                    break;
                case 'delete':
                    $str.=$this->uig->get_linkbutton('删除','###','id="#'.$id.'" title="'.$title.'" onclick="confirmADelete(this,\'?m='.$modname.'_List&action=delete&id=.key.\')"').' ';
                    break;
                case 'add':
                    $str.=$this->uig->get_linkbutton('新增', $adduri?$adduri:'?m='.$modname).' ';
                    break;
                default :
                    $str.=$btn.' ';
                    break;
            }
        }
        return $str;
    }
}

?>
